﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="Person", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(Person))]
    public class PersonSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IPerson clazz;
        
        public PersonSerializer(IPerson clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Gender");
            if (clazz.Gender!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "Gender");
                Writer.WriteString(clazz.Gender.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Gender");
            }
            Writer.WriteEndElement();
            if (clazz.PersonalIDCode!=null) {
                Writer.WriteStartElement("PersonalIDCode");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.PersonalIDCode))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.TimeOfBirth!=null) {
                Writer.WriteStartElement("TimeOfBirth");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "DateTime_String");
                Writer.WriteString(clazz.TimeOfBirth.ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("GivenName");
            if (clazz.GivenName!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.GivenName.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : GivenName");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("SurName");
            if (clazz.SurName!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.SurName.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : SurName");
            }
            Writer.WriteEndElement();
            if (clazz.PopRegData!=null) {
                Writer.WriteStartElement("PopRegData");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "Description");
                Writer.WriteString(clazz.PopRegData.ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Gender") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Person>Gender");
                }
                clazz.Gender = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.Gender(Reader.ReadElementString("Gender"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Person>Gender", Reader.LocalName);
            }
            if (Reader.LocalName=="PersonalIDCode") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Person>PersonalIDCode");
                }
                clazz.PersonalIDCode = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("PersonalIDCode")).Value;
            }
            if (Reader.LocalName=="TimeOfBirth") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Person>TimeOfBirth");
                }
                clazz.TimeOfBirth = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.DateTimeString(Reader.ReadElementString("TimeOfBirth"));
            }
            if (Reader.LocalName=="GivenName") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Person>GivenName");
                }
                clazz.GivenName = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("GivenName"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Person>GivenName", Reader.LocalName);
            }
            if (Reader.LocalName=="SurName") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Person>SurName");
                }
                clazz.SurName = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("SurName"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Person>SurName", Reader.LocalName);
            }
            if (Reader.LocalName=="PopRegData") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Person>PopRegData");
                }
                clazz.PopRegData = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.Description(Reader.ReadElementString("PopRegData"));
            }
        }
    }
}
